//
//  LabelFlowLayout.m
//  15-HomeWork
//
//  Created by dllo on 16/8/3.
//  Copyright © 2016年 LST. All rights reserved.
//

#import "LabelFlowLayout.h"

@interface LabelFlowLayout ()
@property (nonatomic, assign)CGFloat itemWidth;
@property (nonatomic, strong)NSMutableArray<UICollectionViewLayoutAttributes *> *attributesArr;
@end
@implementation LabelFlowLayout


- (instancetype)init {
    self = [super init];
    if (self) {
     _attributesArr = [NSMutableArray array];
    }
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
       _attributesArr = [NSMutableArray array]; 
    }
    return self;
}
- (void)prepareLayout {
    CGFloat width = 0;
    CGFloat x = 0;
    for (int i = 0; i < [self.collectionView numberOfItemsInSection:0]; i++) {
        NSIndexPath *index = [NSIndexPath indexPathForItem:i inSection:0];
        // 创建系统需要的布局描述类
        UICollectionViewLayoutAttributes *layoutAttributes = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:index];
        x = x + width + 10 + 0.5;
        CGFloat y = 0;
        width = [self.delegate collectionView:self.collectionView layout:self height:60 heightForItemAtIndexPath:index] + 10;
        CGFloat height = 60;
        layoutAttributes.frame = CGRectMake(x, y, width, height);
        [_attributesArr addObject:layoutAttributes];
    }

}
- (NSArray<UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect {
    return _attributesArr;
}

- (CGSize)collectionViewContentSize {
    return CGSizeMake(1100, 0);
}
@end
